import {take,call,put,fork} from 'redux-saga/effects';

import {getLogin} from '../../../../../services/pc/member/login';
//登录
function* sagaLogin(){
    while (true){
        let action = yield take("LOGIN");
        let payload = yield call(getLogin, action.data.data);
        let data={}
        if (payload.code===200){
            data.auth_token=payload.data.auth_token;
            data.uId=payload.data.uid;
        }
        yield put({type:'login',data});
        if (action.data.success){
            action.data.success(payload)
        }
    }
}
//退出
function *sagaOotLogin(){
    while (true){
        let action =  yield take('OUTLOGIN');
        let data={
            auth_token:'',
            useId:'',
            useName:'',
            useEmail:'',
            useHeadImg:'',
            useRole:'',
        }
        yield put({type:'outlogin',data})
        if (action.data.success){
            action.data.success()
        }
    }
}
let  aFork=[
    fork(sagaLogin),
    fork(sagaOotLogin),
];
export default aFork;